﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@

@{
    //Layout = "~/Views/Shared/_FormLayout.cshtml";
    Layout = "~/Views/Shared/__ComponentLayout.cshtml";
    string editId = ViewData.Count > 0 ? ViewData["0"].ToString() : "null";
    string randomId = Guid.NewGuid().ToString();

}
@using ST.Torch.WebApi.Application.System.Services
@using ST.Torch.WebApi.Web.Core;
@inject IUIDService uidservice;
@inherits UtilRazorPage<object>
<div style="padding: 16px;"></div>
<form style="padding: 16px;padding-right:30px;background-color:white;margin:30px" class="layui-form EditUserInfoForm" action="" lay-filter="edit-data_@randomId">
    <input type="text" name="Id" placeholder="" autocomplete="off" class="layui-input" style="display:none">

    <div class="layui-form-item">
        <label class="layui-form-label">@L("旧密码")</label>
        <div class="layui-input-block">
            <input type="password" name="OldPass" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">@L("新密码")</label>
        <div class="layui-input-block">
            <input type="password" name="NewPass" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">@L("重复新密码")</label>
        <div class="layui-input-block">
            <input type="password" name="NewPass1" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
   
    <div class="layui-form-item" style="text-align:center">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo_@randomId">@L("确认修改密码")</button>
        </div>
    </div>

</form>


@section footer
{
    <script>
        //
        layui.use(['form', 'toast', 'upload', 'element'], function () {
            var form = layui.form;
            var toast = layui.toast;
            var upload = layui.upload;
            var element = layui.element;

            var editId = editId = '@uidservice.UserId';
            var tempData = { Id: editId }
            form.val("edit-data_@randomId", tempData);
            form.render();

         
            //监听提交
            form.on('submit(formDemo_@randomId)', function (data) {
                if (data.field.NewPass != data.field.NewPass1) {
                    var msgError = '@L("新密码不对")';
                    toast.error({
                        message: msgError,
                    });
                    return false;
                }
                G_UpdatePass(data);
                
                return false;
            });

   
            function G_UpdatePass(data) {
                $.ajax({
                    type: 'POST',
                    url: '/api/SYSUser/UpdatePassword',//发送请求
                    data: data.field,
                    success: function (result) {
                        console.log(result)
                        if (result.Succeeded) {
                            toast.success({
                                message: '@L("修改成功")',
                            });
                        } else {
                            var msgError = '@L("修改失败")';
                            if (result.Errors != "") {
                                msgError = result.Errors
                            }
                            toast.error({
                                message: msgError,
                            });

                        }
                    }
                });
            }


        });
    </script>
}